package com.voute.View.Activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.voute.Base.BaseActivity;
import com.voute.R;

/**
 * 共通webview Activity
 * Created by liucxu on 2017/1/21.
 */

public class WebViewActivity extends BaseActivity {
private RelativeLayout back_layout;
    private TextView title_tv;
    private WebView webview;

    @Override
    public int getLayoutId() {
        return R.layout.activity_webview;
    }

    @Override
    public void setupView() {
        back_layout=$(R.id.back_layout);
        title_tv=$(R.id.title_tv);
        webview=$(R.id.webview);
        back_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                WebViewActivity.this.finish();
            }
        });

        WebSettings wSet = webview.getSettings();
        wSet.setJavaScriptEnabled(true);
        webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                //重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }
        });

        Intent intent=getIntent();
        String title=intent.getStringExtra("webview_title");
        String url=intent.getStringExtra("webview_url");
        if(TextUtils.isEmpty(title)||TextUtils.isEmpty(url)){
            WebViewActivity.this.finish();
        }
        else{
            title_tv.setText(title);
            webview.loadUrl(url);
        }
    }

    @Override
    public void setupData() {

    }
}
